//
//  TextAndImageTableViewCell.m
//  UI12_homework_网易
//
//  Created by aaaaaa on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TextAndImageTableViewCell.h"
#import "JokesModel.h"
#import "GetHeightTools.h"
#import "UIImageView+WebCache.h"
#import "CustomView.h"

@interface TextAndImageTableViewCell ()

@property (nonatomic, retain) UILabel *lable;
@property (nonatomic, retain) UIImageView *customImageView;
@property (nonatomic, retain) CustomView *customView;

@end



@implementation TextAndImageTableViewCell

- (void)dealloc
{
    [_lable release];
    [_customImageView release];
    [_customView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.lable = [[UILabel alloc] init];
        [self.contentView addSubview:self.lable];
        [_lable release];
        
        self.customImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.customImageView];
        [_customImageView release];
        
        self.customView = [[CustomView alloc] init];
        [self.contentView addSubview:self.customView];
        [_customView release];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.lable.numberOfLines = 0;
    CGFloat textHeight = [GetHeightTools getTextHeight:self.jokesModel.digest];
    self.lable.frame = CGRectMake(5, 10, [UIScreen mainScreen].bounds.size.width - 10, textHeight);
    
    CGFloat imageHeight = [GetHeightTools getImageHeight:self.jokesModel.img];
    self.customImageView.frame = CGRectMake(0, textHeight + 10, [UIScreen mainScreen].bounds.size.width, imageHeight);
 
    self.customView.frame = CGRectMake(0, textHeight + imageHeight + 10, [UIScreen mainScreen].bounds.size.width, 50);
    [self.customView createSubViews];
}

- (void)setJokesModel:(JokesModel *)jokesModel{
    if (_jokesModel != jokesModel) {
        [_jokesModel release];
        _jokesModel = [jokesModel retain];
    }
    
    NSURL *url = [NSURL URLWithString:jokesModel.img];
    
    self.lable.text = jokesModel.digest;
    [self.customImageView sd_setImageWithURL:url];
    
    self.customView.jokesModel = jokesModel;
    
    
}




























@end
